package com.shdanyan.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.shdanyan.domain.sys.SysUserInfo;
import com.shdanyan.service.UserInfoService;

@Service
public class CustomUserDetailsService implements UserDetailsService {

    @Autowired
    private UserInfoService userInfoService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUserInfo user = userInfoService.findByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException("用户账号 " + username + " 不存在");
        }
        return new SecurityUser(user);
    }

}
